package com.ruoyi.web.controller.comlbs;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Agreement;
import com.ruoyi.system.service.IAgreementService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 设备接入协议Controller
 * 
 * @author wp
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/comlbs/agreement")
public class AgreementController extends BaseController {

    @Autowired
    private IAgreementService agreementService;

    @ApiOperation("协议列表")
    @ApiOperationSupport(includeParameters = {"agreementName", "type"})
    @GetMapping("/list")
    public TableDataInfo list(Agreement agreement) {
        startPage();
        List<Agreement> list = agreementService.selectList(agreement);
        return getDataTable(list);
    }

    /**
     * 获取设备接入协议详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(agreementService.getById(id));
    }

    @ApiOperation("新增设备接入协议")
    @ApiOperationSupport(includeParameters = {"agreementName","domain","ip","port","type","remark"})
    @Log(title = "设备接入协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Agreement agreement) {
        return toAjax(agreementService.save(agreement));
    }

    @ApiOperation("编辑设备接入协议")
    @ApiOperationSupport(includeParameters = {"id","agreementName","domain","ip","port","type","remark"})
    @Log(title = "设备接入协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Agreement agreement) {
        return toAjax(agreementService.updateById(agreement));
    }

    @ApiOperation("删除设备接入协议")
    @Log(title = "设备接入协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(agreementService.removeByIds(Arrays.asList(ids)));
    }
}
